﻿using System;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;

namespace MapleLeaf.Pay {
    // Token: 0x0200000C RID: 12
    public class SignMessage {
        // Token: 0x17000002 RID: 2
        // (get) Token: 0x06000053 RID: 83 RVA: 0x000023ED File Offset: 0x000005ED
        // (set) Token: 0x06000054 RID: 84 RVA: 0x000023F5 File Offset: 0x000005F5
        public string Id { get; set; }

        // Token: 0x17000003 RID: 3
        // (get) Token: 0x06000055 RID: 85 RVA: 0x000023FE File Offset: 0x000005FE
        // (set) Token: 0x06000056 RID: 86 RVA: 0x00002406 File Offset: 0x00000606
        public string Salt { get; set; }

        // Token: 0x17000004 RID: 4
        // (get) Token: 0x06000057 RID: 87 RVA: 0x0000240F File Offset: 0x0000060F
        // (set) Token: 0x06000058 RID: 88 RVA: 0x00002417 File Offset: 0x00000617
        public string Signature { get; set; }

        // Token: 0x17000005 RID: 5
        // (get) Token: 0x06000059 RID: 89 RVA: 0x00002420 File Offset: 0x00000620
        // (set) Token: 0x0600005A RID: 90 RVA: 0x00002428 File Offset: 0x00000628
        public string Content { get; set; }

        // Token: 0x17000006 RID: 6
        // (get) Token: 0x0600005B RID: 91 RVA: 0x00002431 File Offset: 0x00000631
        // (set) Token: 0x0600005C RID: 92 RVA: 0x00002439 File Offset: 0x00000639
        public long TimeStamp { get; set; }

        // Token: 0x0600005D RID: 93 RVA: 0x000040E0 File Offset: 0x000022E0
        public override string ToString() {
            return this.JsonEncode(Formatting.None);
        }

        // Token: 0x0600005E RID: 94 RVA: 0x000040F8 File Offset: 0x000022F8
        public SignMessage Sign(string secret) {
            Salt = Guid.NewGuid().ToString("N");
            TimeStamp = MapleLeaf.Pay.TimeStamp.Now / 1000L;
            Signature = GetSignString(GetSignBody(secret));
            return this;
        }

        // Token: 0x0600005F RID: 95 RVA: 0x00004148 File Offset: 0x00002348
        public string GetSignBody(string secret) {
            return string.Join(Environment.NewLine, new object[]
            {
                Content,
                Id,
                Salt,
                secret,
                TimeStamp
            });
        }

        // Token: 0x06000060 RID: 96 RVA: 0x00004194 File Offset: 0x00002394
        public bool SignVerify(string secret) {
            string signString = GetSignString(GetSignBody(secret));
            return Signature == signString;
        }

        // Token: 0x06000061 RID: 97 RVA: 0x000041BC File Offset: 0x000023BC
        private static string GetSignString(string sign_body) {
            return MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(sign_body)).HexEncode();
        }

        // Token: 0x06000062 RID: 98 RVA: 0x0000231F File Offset: 0x0000051F
        public SignMessage() {
            Class18.LVfVa0hzXO4Jq();
        }
    }
}
